import yfinance as yf
import pandas as pd
from sqlalchemy import create_engine
Trumpinys = ["^GSPC"]
df_list = list()
for ticker in Trumpinys:
data = yf.download(ticker, period='30y')
data['ticker'] = ticker
df_list.append(data)
data.drop(['High', 'Low', 'Adj Close', 'ticker', 'Volume'], axis='columns', inplace=True)
df = pd.concat(df_list)
sp500 = pd.DataFrame(data=df)
engine = create_engine("mysql+pymysql://root:slaptazodis@127.0.0.1:3317/sp500")
dbConnection = engine.connect()
sp500.to_sql('sp501', engine, index=True, if_exists='append')